package com.kaifamiao.demo.d0809.ex;

import com.kaifamiao.demo.d0809.Person;

public class Demo04 {


    public static void main(String[] args) throws ClassNotFoundException {
        /*
            抛异常 throw  throws
            throw 表示人为抛出一个异常对象
            throws 表示声明方法可能会产生一个异常
         */

//        add(-1, "a");

        try {
            setAge(1000);
        } catch (AgeException e) {
            e.printStackTrace();
        }


        setGender("11");

    }

    public static void setGender(String gender){
        if("男".equals(gender) || "女".equals(gender)){

        } else {
            throw new GenderException();
        }
    }

    public static void setAge(int age) throws AgeException {
        if (age < 0 || age > 120){
            throw new AgeException("年龄不对, age = " + age);
        }
    }

    public static void add(int index, String Object) throws RuntimeException, NullPointerException {
        if (index < 0 || index > 10){
//            throw new IndexOutOfBoundsException();
//            throw new RuntimeException("下标不符合要求: " + index);
            throw new Error("index 有问题");
        }
    }
}

interface A {
    void test() throws RuntimeException;
}
